package com.metadata_system.common.db.mapper;

import com.metadata_system.common.db.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface UserMapper extends Mapper<User> {
    @Select("select count(*) FROM md_user WHERE username=#{username} AND user_type=#{userType}")
    int countByUsernameAndUserType(
            @Param("username") String username,
            @Param("userType") String userType
    );


    @Select("select id FROM md_user WHERE username=#{username} AND user_type=#{userType}")
    int selectIdByUsernameAndUserType(
            @Param("username") String username,
            @Param("userType") String userType
    );


    @Select("SELECT LAST_INSERT_ID();")
    int getLastInsertId();

    @Select("SELECT id FROM md_user WHERE username=#{username} AND user_type=#{userType} AND params=#{params}")
    Integer getUserId(String userType, String username, String params);

    @Select("SELECT id FROM md_user WHERE user_type=#{userType} AND role=#{role} LIMIT 10")
    List<Integer> getUserIdListByUserTypeRole(String userType, String role);

    @Select("SELECT role FROM md_user WHERE id=#{id}")
    String getRoleById(@Param("id") Integer id);

}
